package morphage.gui;

import java.awt.*;

import javax.swing.*;

import morphage.engine.ImageManager;

public class GUI extends JApplet {

	private static final long serialVersionUID = 1L;
	
	public static final String 		APP_NAME	= "MORPHAGE";
	
	private 	static 	GUI					s_instance = new GUI();
	private 			JFrame 					m_frame;
	private 			AppMainPanel 		m_mainPanel;
	private 			AppMenuBar			m_appMenuBar;
	
	public static JFrame getFrame() { return getInstance().m_frame; }
	
	private void initFrame()
	{
		System.out.println("BEGIN window initialization");
		
		
		
		m_frame 			= new JFrame(APP_NAME);
		m_mainPanel		= new AppMainPanel();
		m_appMenuBar	= new AppMenuBar();
		m_frame 			.setJMenuBar( m_appMenuBar );
		m_frame				.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		m_frame       .getContentPane()	.setLayout(new BorderLayout());
		m_frame       .getContentPane()	.add("Center", m_mainPanel);
		//JFrame.setDefaultLookAndFeelDecorated(true);
		
	  m_frame				.pack();
	  
		centerFrame();
		m_frame				.setVisible(true);
		System.out.println("END window initialization");
		System.out.println("RUNNING ...");
		try{
	    ImageManager.loadFirstImage("./examples/refactored_kidman.jpg");
	    ImageManager.loadLastImage("./examples/reveil_F3.jpg");
	    }catch(Exception ex){}
	}
	
	private void centerFrame()
	{
		//Center frame
		Dimension screenSize 	= Toolkit.getDefaultToolkit().getScreenSize();
		Dimension size 				= m_frame.getSize();
		screenSize.height 		= screenSize.height/2;
		screenSize.width 			= screenSize.width/2;
		size.height 					= size.height/2;
		size.width 						= size.width/2;
		int y 								= screenSize.height - size.height;
		int x 								= screenSize.width - size.width;
		m_frame.setLocation(x, y);
	}
	
	public static GUI getInstance() 
	{
		if (s_instance == null) s_instance = new GUI();
		return s_instance; 
	}
	
	public static void main(String[] args) 
	{
		getInstance().initFrame();
	}

}
